Skip to content

feat(telemetry): derive failure_kind for run telemetry - #704

Merged
neubig merged 2 commits into
mainfrom
feat/run-failure-kind-telemetry
Nov 14, 2026
Merged

neubig merged 2 commits into
mainfrom
feat/run-failure-kind-telemetry

Conversation

@neubig

@neubig neubig commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Why

PostHog (Agent Canvas project) shows automation_run_failed firing ~294k times per 90 days with no error_kind/failure_reason property at all, so run-failure analysis is impossible. The signal exists — the service stores free-text error_detail on the run and three emission sites already set a partial failure_kind — but nothing normalizes it, and the raw detail text (paths, URLs, script output) must never reach telemetry anyway.

Discussed in Slack: https://allhandsai.slack.com/archives/C0BGK8NRYUX/p1793909181285009

Summary

  • telemetry.py: new _failure_kind_from_error_detail() maps the closed set of prefixes this service writes to a coarse, non-identifying category: Timed out: verification failed… → verification_failed, Timed out:… → timeout, Cancelled… → cancelled, Failed to get execution context → dispatch_error, anything else → execution_error, empty → no property.
  • _base_properties() attaches the derived failure_kind whenever a run carries an error_detail, so every emission site (router callback, watchdog verification/timeout, dispatcher) gains it automatically — including the sites that set nothing today. Explicit per-site failure_kind properties still override via the existing property-merge order.
  • The free-text error_detail itself is never sent; only the closed-set category.

Tests

  • 8 new parametrized cases for the classifier in tests/test_telemetry.py, plus a base-properties test asserting the derived kind is present and the raw detail (including a planted secret path) does not leak into properties.
  • uv run python -m pytest tests/test_telemetry.py -q → 26 passed.

Notes

This PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.

Issue tracking

Part of OpenHands/automation#266 — Make terminal telemetry usable for unique-user automation funnels. This PR contributes to the shared tracker; merging it must not close the umbrella by itself.

This tracking update was made by an AI agent (OpenHands) on behalf of Graham Neubig.

Jev-Fast-Audit

⚡ Jev fast audit · estimates · 0.23s · commit 2a8cfe5
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage: complete supplied coverage; 3/3 hunks, 2/2 files.

All estimates and evidence
Estimate Likelihood / value Direct evidence
SQL injection 3.0% No direct hunk selected
Command injection 3.0% No direct hunk selected
Weakened authentication 3.0% No direct hunk selected
Weakened authorization 4.0% No direct hunk selected
Contract regression 7.0% No direct hunk selected
Data loss 3.0% No direct hunk selected
Sensitive data disclosure 4.0% No direct hunk selected
Unexpected data transfer 4.0% No direct hunk selected
Credential misuse 5.0% No direct hunk selected
Untrusted instruction authority 2.0% No direct hunk selected
Package source redirection 3.0% No direct hunk selected
Unverified remote execution 2.0% No direct hunk selected
Privileged environment access 2.0% No direct hunk selected
Security assessment bypass 4.0% No direct hunk selected
Prohibited workload 2.0% No direct hunk selected
Primary concern None selected; confidence 93.0% No primary concern to locate

automation_run_failed fires ~294k times per 90 days in PostHog with
no error_kind/failure_reason, so failure analysis is impossible.
Derive a closed-set failure_kind (timeout, verification_failed,
dispatch_error, cancelled, execution_error) from the stored
error_detail prefix in _base_properties, so every emission site
(callback, watchdog, dispatcher) gains it automatically. The
free-text error_detail itself is never sent to telemetry.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions github-actions Bot added the type: feat A new feature label Nov 5, 2026
@neubig
neubig requested a review from malhotra5 November 6, 2026 17:51
@neubig
neubig marked this pull request as ready for review November 6, 2026 17:51
Preserve failure classification alongside SDK version caching and run-as telemetry.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Coverage

Warning

Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it.

@neubig
neubig requested a review from all-hands-bot November 6, 2026 18:26

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was posted by an AI agent (OpenHands).

Fresh review of head 2a8cfe5. The change is correctly scoped to this repository: it normalizes error_detail on automation runs into a coarse, non-identifying failure_kind for PostHog telemetry, which is squarely in this service's ownership.

Verified against the workspace code:

  • Prefix coverage matches the real writers. Timed out: verification failed: … (watchdog.py:260) → verification_failed; Timed out: … (watchdog.py:325, 516) → timeout; Cancelled by user (router.py:1945) → cancelled; Failed to get execution context (dispatcher.py:1061) → dispatch_error; everything else → execution_error. The classifier checks the more specific verification_failed prefix before the generic Timed out:, so ordering is correct.
  • Override semantics preserved. _capture_automation_event builds base properties first and then applies caller properties, so the explicit per-site failure_kind values in watchdog.py:279/:549 and dispatcher.py:812 still win, and they agree with what the classifier derives from the same rows.
  • No PII/secret leakage path. _failure_kind_from_error_detail returns only literal closed-set strings; the raw free-text error_detail (which includes paths, stderr, callback errors) never enters properties. The new test plants a secret-like path and asserts it is absent, consistent with the repo guidance against persisting plaintext sensitive content in telemetry.
  • Reconciled-callback interaction is safe. When the completion callback flips a watchdog-timeout back to COMPLETED, error_detail is cleared (router.py:1727), so no stale failure_kind attaches to the completed event.
  • Tests. uv run python -m pytest tests/test_telemetry.py -q → 29 passed in the workspace. Dispatcher/router suites requiring the session postgres_container fixture could not run here (no Docker daemon in this environment) — that is a pre-existing environment limitation, not a PR issue; the unit-tests GitHub Actions check on this exact head is green and covers them, and the Failed to get execution context prefix is additionally asserted in tests/test_dispatcher.py:1685.

No material findings.

✅ APPROVED

@neubig

neubig commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Live production-path evidence (2026-11-13)

Validated head 2a8cfe5176692e4e0158e26fdb0b3ed1e6fe68e9 using the existing automation Python environment and importing this PR checkout directly.

  • PYTHONPATH="$PWD" /home/gneubig/work/automation/.venv/bin/python -m pytest tests/test_telemetry.py -q: 29 passed.
  • Executed the real capture_automation_event production function, with real SQLAlchemy/aiosqlite metadata/consent storage and a real loopback HTTP server receiving /capture/ POSTs. No monkeypatch or mock HTTP transport was used.
  • 8 HTTP POSTs received: missing/empty error omits failure_kind; verification failure, timeout, cancellation, dispatch failure and generic execution failure map to the expected categories; explicit caller properties still override the derived value.
  • A synthetic raw-error canary was absent from every captured JSON payload. Revoking persisted consent resulted in no additional HTTP request.
  • Receiver was loopback-only with a synthetic capture key; no real PostHog project was contacted. No automation was created, deployed, enabled or dispatched. This validates the changed event-emission path, not a full cloud sandbox run.

Current-head independent approvals already exist, so no additional review was requested. No code change was needed.

Generated by an AI agent (OpenHands) on behalf of neubig.

@neubig
neubig merged commit 0674c5f into main Nov 14, 2026
17 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.33.0 Shipped in 1.33.0 label Nov 17, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.33.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.33.0 Shipped in 1.33.0 type: feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants